<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图书管理</title>
	<%-- 静态包含头部信息--%>
	<%@include file="/pages/common/header.jsp"%>

	<%-- 增加 删除 按钮的 确认窗口	--%>
	<script type="text/javascript">
		$(function () {
			// 绑定单击事件
			$("a.deleteClass").click(function () {
				// 通过当前的 dom 对象获取 要删除的 商品名称
				return confirm("确定删除["+ $(this).parent().parent().find("td:first").text() +"]?");
			})

			// 绑定单击事件， 跳到 指定的页码
			$("#searchPageBtn").click(function () {
				var pageNo = $("#pn_input").val();

				// 处理跳转的页码超出边界的情况
				if(pageNo < 1) pageNo = 1;
				if(pageNo > ${requestScope.page.pageTotal}) pageNo = ${requestScope.page.pageTotal};

				// 将地址改为动态
				// location.href = "http://localhost:8080/book/manager/bookServlet?action=page&pageNo=" + pageNo;
				location.href = "${pageScope.base}manager/bookServlet?action=page&pageNo=" + pageNo;
			})
		})
	</script>
</head>
<body>

	<div id="header">
			<img class="logo_img" alt="" src="../../static/img/logo.gif" >
			<span class="wel_word">图书管理</span>
			<!-- 静态包含菜单管理页面 -->
			<%@include file="/pages/common/manaer_menu.jsp"%>
	</div>

	<div id="main">
		<table>
			<tr>
				<td>书名</td>
				<td>金额</td>
				<td>作者</td>
				<td>销量</td>
				<td>库存</td>
				<td>点击修改</td>
				<td>点击删除</td>
			</tr>
		<%--			<c:forEach items="${requestScope.books}" var="book">--%>
			<c:forEach items="${requestScope.page.items}" var="book">
				<tr>
					<td>${book.name}</td>
					<td>${book.price}</td>
					<td>${book.author}</td>
					<td>${book.sales}</td>
					<td>${book.stock}</td>
					<!-- 增加 一个方法，通过id获取商品信息，转发给 edit.jsp -->
					<td><a href="manager/bookServlet?action=getBook&id=${book.id}&pageNo=${requestScope.page.pageNo}">修改</a></td>
					<td><a class="deleteClass" href="manager/bookServlet?action=delete&id=${book.id}&pageNo=${requestScope.page.pageNo}">删除</a></td>
				</tr>
			</c:forEach>

			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<%-- 添加商品后，显示最后一页--%>
				<td><a href="pages/manager/book_edit.jsp?pageNo=${requestScope.page.pageTotal}">添加图书</a></td>
			</tr>
		</table>

		<!-- 静态包含分页条 -->
		<%@include file="/pages/common/page_nav.jsp"%>

	</div>

	<%--静态包含页脚信息--%>
	<%@include file="/pages/common/footer.jsp"%>
</body>
</html>